package com.ygxsk.carhome.ui.member;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.gyf.immersionbar.ImmersionBar;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.enumwrap.MemberLevel;
import com.ygxsk.carhome.response.MemberItemBean;
import com.ygxsk.carhome.ui.ErrorActivity;
import com.ygxsk.carhome.ui.adapter.MemberListAdapter;
import com.ygxsk.carhome.views.MyLinearLayoutManager;
import com.ygxsk.carhome.views.picker.NomalCustomBean;
import com.ygxsk.carhome.views.spinner.NiceSpinnersk;

import java.util.ArrayList;

import butterknife.BindView;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-07-29  21:17
 * @Description:会员管理的主页列表；
 */
public class MemberMainListActivity extends ErrorActivity {


    @BindView(R.id.refreshlayoutinmemberlist)
    SmartRefreshLayout refreshLayoutInMemberList;

    @BindView(R.id.recyclerviewinmemberlist)
    RecyclerView recyclerViewInMemberList;

    //这种将来可能没有这种类型；
    //选择类型
    @BindView(R.id.nice_spinner_type_member)
    NiceSpinnersk nice_spinner_type_member;
    //选择来源
    @BindView(R.id.nice_spinner_state_member)
    NiceSpinnersk nice_spinner_state_member;
    //选择状态
    @BindView(R.id.nice_spinner_other_member)
    NiceSpinnersk nice_spinner_other_member;


    private ArrayList<MemberItemBean> mDataResources = new ArrayList<>();

    //筛选条件的 汽车的类型；
    private ArrayList<NomalCustomBean> dataListCarType = new ArrayList<>();
    //客户的来源
    private ArrayList<NomalCustomBean> dataListFromWhere = new ArrayList<>();
    //该客户的分配状态
    private ArrayList<NomalCustomBean> dataListStateItem = new ArrayList<>();

    //适配器
    private MemberListAdapter memberListAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        mActivityInstance = this;

        initViews();


    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_member_main_list;
    }

    @Override
    protected void initToolBar(ToolbarHelper toolbarHelper) {

        toolbarHelper.setTitle(getString(R.string.add_submit_auth_manage));
        toolbarHelper.setVersionName(true, AppUtils.getAppVersionName());
        toolbarHelper.setLayoutClose(false, "", null);

        toolbarHelper.setLayoutLeft(true, R.drawable.backicon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //搜索客户信息，优先关闭软键盘
                KeyboardUtils.hideSoftInput(mActivityInstance);
                methodBack();
            }
        });

        toolbarHelper.setLayoutRight(false, 0, "", null);

    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();

        ImmersionBar.with(this)//
                .titleBar(R.id.toolbarygxskout)
                .fitsSystemWindows(true)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                //.statusBarColor(R.color.colorPrimary)//
                //.navigationBarColor(R.color.colorPrimary)//
                //.keyboardEnable(true)
                .init();
    }

    @Override
    protected void onClickNodata(View v) {

    }

    @Override
    protected void initViews() {

        //几个筛选条件或者搜索逻辑布局
        // TODO: 2023-07-13 15:55 假数据
        MemberItemBean memberItemBean = new MemberItemBean();
        memberItemBean.setMemberLevelInfo("vip1");
        memberItemBean.setPersonPhone("17531108969");
        memberItemBean.setPersonName("陈大");
        memberItemBean.setMemberLevel(MemberLevel.Level_1.getValue());//会员的等级标志，不是文本类

        MemberItemBean leadListItemBean1 = new MemberItemBean();
        leadListItemBean1.setMemberLevelInfo("vip2");
        leadListItemBean1.setPersonPhone("17531108969");
        leadListItemBean1.setPersonName("陈大");
        leadListItemBean1.setMemberLevel(MemberLevel.Level_1.getValue());//会员的等级标志，不是文本类

        MemberItemBean leadListItemBean2 = new MemberItemBean();
        leadListItemBean2.setMemberLevelInfo("vip2");
        leadListItemBean2.setPersonPhone("17531108969");
        leadListItemBean2.setPersonName("陈大");
        leadListItemBean2.setMemberLevel(MemberLevel.Level_1.getValue());//会员的等级标志，不是文本类


        mDataResources.add(memberItemBean);
        mDataResources.add(leadListItemBean1);
        mDataResources.add(leadListItemBean2);


        recyclerViewInMemberList.setLayoutManager(new MyLinearLayoutManager(this));

        memberListAdapter = new MemberListAdapter(R.layout.memberlistadapter, mDataResources);
        recyclerViewInMemberList.setAdapter(memberListAdapter);

        memberListAdapter.notifyDataSetChanged();

        memberListAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

                // TODO: 2023-07-13 15:07 跳转到这个客户的详情页面
                Bundle extra_bundle = new Bundle();

//                extra_bundle.putParcelable(ExtraKey.EXTRA_RUNMANGROUPMANAGEBEAN, runManGroupManageBeanItem);

//                ActivityUtils.startActivity(extra_bundle, LeadDetailActivity.class);

            }
        });

        refreshLayoutInMemberList.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

                refreshLayout.getLayout().post(new Runnable() {
                    @Override
                    public void run() {

                        if (mDataResources != null && !mDataResources.isEmpty()) {
                            mDataResources.clear();
                        }

                        // TODO: 2023-07-13 15:11 待处理

//                        getServerDatas();

                        refreshLayout.finishRefresh();
                    }
                });

            }

            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

                refreshLayout.getLayout().post(new Runnable() {
                    @Override
                    public void run() {

                        //最后一条数据的id信息；
                        //getServerDatas(repairIdPass);

                        refreshLayout.finishLoadMore();

                    }
                });
            }
        });


    }

    @Override
    protected void gainDatas() {

    }

    @Override
    protected void methodBack() {

    }
}